//package com.yuan.spring.messagequeue.redisqueue;
//
//import com.yuan.spring.util.ApplicationUtil;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.listener.PatternTopic;
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
//import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
//
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
///**
// * @RedisListen
// * @RedisChat 注解支持
// * Created by 袁恩光 on 2017/12/8.
// */
//@Configuration
//public class RedisAnnotationConfig {
//
//    /**
//     * 注册所有方法
//     */
//    @Bean
//    public RedisMessageListenerContainer initListenAdapter() {
//        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
//        Map<String, Object> redisListens = ApplicationUtil.getBeansWithAnnotation(RedisListen.class);
//        RedisConnectionFactory redisConnectionFactory = ApplicationUtil.getBean(RedisConnectionFactory.class);
//        redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
//        for (String key : redisListens.keySet()) {
//            Object object = redisListens.get(key);
//            //获取注解属性
//            RedisListen redisListen = object.getClass().getAnnotation(RedisListen.class);
//            //获取方法 默认注册所有该类下的方法 (取出默认方法)
//            Method[] methods = object.getClass().getMethods();
//            for (Method method : methods) {
//                String[] chat = redisListen.value();
//                if (method.getName().matches("wait|equals|toString|hashCode|getClass|notify|notifyAll")) {
//                    continue;
//                }
//                //获取方法注解
//                RedisChat redisChat = method.getAnnotation(RedisChat.class);
//                if (null != redisChat) {
//                    chat = redisChat.value();
//                }
//                List<PatternTopic> patternTopicList = new ArrayList<>();
//                for (String strChat : chat) {
//                    patternTopicList.add(new PatternTopic(strChat));
//                }
//                MessageListenerAdapter messageListenerAdapter = ApplicationUtil.registerBean(MessageListenerAdapter.class,
//                        "messageListenerAdapter" + method.getName(), object, method.getName());
//                redisMessageListenerContainer.addMessageListener(messageListenerAdapter, patternTopicList);
//            }
//        }
//        return redisMessageListenerContainer;
//    }
//
//
//}
